import React, { Component } from 'react';
import { View } from 'react-native';
import { Provider } from 'react-redux';
import CodePush from 'react-native-code-push';
import App from './components/App';
import store from './store';
import Base from './utils/Base';

global.Base = Base;
global.storage = Base.storage;

const codePushOptions = {
  checkFrequency: CodePush.CheckFrequency.ON_APP_RESUME,
};
class Index extends Component {
  componentWillMount() {
    CodePush.disallowRestart();
    this.syncImmediate();
  }
  syncImmediate = () => {
    CodePush.sync({
      installMode: CodePush.InstallMode.IMMEDIATE,
      updateDialog: {
        appendReleaseDescription: true,
        descriptionPrefix: '更新内容：',
        mandatoryContinueButtonLabel: '立即更新',
        mandatoryUpdateMessage: '必须更新后才能使用',
        optionalIgnoreButtonLabel: '稍后',
        optionalInstallButtonLabel: '后台更新',
        optionalUpdateMessage: '有新版本了，是否更新？',
        title: '更新提示',
      },
    },
    );
  }
  componentDidMount() {
    CodePush.allowRestart();
  }
  render() {
    return (
      <View style={{ flex: 1 }}>
        <Provider store={store}>
          <App />
        </Provider>
      </View>
    );
  }
}
const NewIndex = CodePush(codePushOptions)(Index);
export default NewIndex;
